FROM rust:1.74 as builder
WORKDIR /usr/src/myapp

ARG DB_URL 
# RUN mkdir /root/.cargo \
#  && echo 'registry = "https://github.com/rust-lang/crates.io-index"' > /root/.cargo/config \
#  && echo 'replace-with = "ustc"' >> /root/.cargo/config \
#  && echo '[source.ustc]' >> /root/.cargo/config \
#  && echo 'registry = "git://mirrors.ustc.edu.cn/crates.io-index"' >> /root/.cargo/config 

COPY ./Cargo.toml ./Cargo.lock ./config.toml ./
COPY ./src ./src

# 这个地址应该是docker gate的地址，不能是localhost
ENV DATABASE_URL=$DB_URL

RUN cargo build --release --locked 


RUN cargo build --release  

FROM ubuntu:24.04
WORKDIR /root/app
COPY --from=builder /usr/src/myapp/target/release/app /usr/src/myapp/target/release/app.d ./
COPY --from=builder /usr/src/myapp/config.toml ./

CMD ["./app"]

